package com.ruoyi.system.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.common.core.domain.entity.SysDept;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
public class TreeListDept implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private Long deptId;
    private Long parentId;
    private String ancestors;
    private String deptShortName;
    private String deptFullName;
    private String deptType;
    private Integer orderNumber;
    private String leader;
    private String phone;
    private String email;
    private String logo;
    private Long geographicalId;
    private String address;
    private Integer isFrozen;
    private Integer isDelete;
    private Integer isCompany;
    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeListDept> children;

    public TreeListDept(SysDept dept) {
        this.id = dept.getDeptId();
        this.deptId = dept.getDeptId();
        this.parentId = dept.getParentId();
        this.ancestors = dept.getAncestors();
        this.deptShortName = dept.getDeptShortName();
        this.deptFullName = dept.getDeptFullName();
        this.deptType = dept.getDeptType();
        this.orderNumber = dept.getOrderNumber();
        this.leader = dept.getLeader();
        this.phone = dept.getPhone();
        this.email = dept.getEmail();
        this.logo = dept.getLogo();
        this.geographicalId = dept.getGeographicalId();
        this.address = dept.getAddress();
        this.isFrozen = dept.getIsFrozen();
        this.isDelete = dept.getIsDelete();
        this.isCompany = dept.getIsCompany();
        if (dept.getChildren() != null) {
            this.children = dept.getChildren().stream().map(TreeListDept::new).collect(Collectors.toList());
        }
    }
}
